<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopActivitySigninTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_activity_signin', ['comment' => '活动签到', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('activity_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '活动'])
            ->addColumn('date', 'string', ['limit' => 30, 'default' => '', 'comment' => '签到日期'])
            ->addColumn('score', 'integer', ['limit'  =>  10, 'default' => 0, 'comment' => '所得积分'])
            ->addColumn(Column::tinyInteger('is_replenish')->setDefault(0)->setUnsigned()->setComment('是否补签:0=正常,1=补签'))
            ->addColumn('rules', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '规则'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('user_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_activity_signin');
        $table->drop();
    }
}
